package com.smart.web.listener;

import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

import com.smart.core.SpringContext;
import com.smart.model.VisitRecord;
import com.smart.service.VisitRecordService;

/**
 * session属性变化监听器
 * 
 * @author Sunxin
 *
 */
public class SessionAttributeChangedListener implements HttpSessionAttributeListener{

	@Override
	public void attributeAdded(HttpSessionBindingEvent event) {
		String attrName = event.getName();
		if("clientIp".equals(attrName)) {
			VisitRecordService visitRecordService = SpringContext.getBean(VisitRecordService.class);
			VisitRecord record = new VisitRecord();
			record.setIp((String) event.getValue());
			visitRecordService.save(record);
		}
	}

	@Override
	public void attributeRemoved(HttpSessionBindingEvent event) {
		
	}

	@Override
	public void attributeReplaced(HttpSessionBindingEvent event) {
		
	}

}
